<?php
/**
 * 行业新闻管理
 */
namespace app\admin\controller;

use think\Request;
use app\admin\service\CryptoNews as CryptoNewsService;
use app\admin\validate\CryptoNews as CryptoNewsValidate;

class CryptoNews extends BaseController
{
    /**
     * 获取新闻列表
     * @param Request $request
     * @param CryptoNewsService $CryptoNewsService
     * @param CryptoNewsValidate $validate
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getList(Request $request,CryptoNewsService $CryptoNewsService,CryptoNewsValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('search')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }

        $param['title_cn'] =  $request->param('title_cn',null);
        $param['source'] =  $request->param('source',null);
        $param['start_date'] =  $request->param('start_date',null);
        $param['end_date'] =  $request->param('end_date',null);

        $intPage =  $request->param('pageIndex',1);
        $intPageSize =  $request->param('pageSize',50);
        $arrData = $CryptoNewsService->getList($param,(int)$intPage,(int)$intPageSize);
        return json($arrData);
    }

    /**
     * 获取字段枚举
     * @param Request $request
     * @param CryptoNewsValidate $validate
     * @param CryptoNewsService $CryptoNewsService
     * @return \think\response\Json
     */
    public function getFieldEnum(Request $request,CryptoNewsValidate $validate,CryptoNewsService $CryptoNewsService)
    {
        $param['field'] =  $request->param('field','ALL');
        $arrData = $CryptoNewsService->getFieldEnum($param['field']);
        return json($arrData);
    }

    /**
     * 获取详情
     * @param Request $request
     * @param CryptoNewsService $CryptoNewsService
     * @param CryptoNewsValidate $validate
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 2024-10-23 15:35:15
     * author: jiang
     */
    public function getInfo(Request $request,CryptoNewsService $CryptoNewsService,CryptoNewsValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('show')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['operator_id'] = $request->operator_id;
        $param['id'] = $request->param('id',null);
        $arrData = $CryptoNewsService->getInfo($param);
        return json($arrData);
    }

    /**
     * 批量修改状态
     * @param Request $request
     * @param CryptoNewsService $CryptoNewsService
     * @param CryptoNewsValidate $validate
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 2024-10-23 15:35:03
     * author: jiang
     */
    public function status(Request $request,CryptoNewsService $CryptoNewsService,CryptoNewsValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('status')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['operator_id'] = $request->operator_id;
        $param['ids'] = $request->param('ids',[]);
        $param['status'] = $request->param('status',null);
        $arrData = $CryptoNewsService->status($param);
        return json($arrData);
    }

    /**
     * 删除
     * @param Request $request
     * @param CryptoNewsService $CryptoNewsService
     * @param CryptoNewsValidate $validate
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 2024-10-23 15:34:50
     * author: jiang
     */
    public function delete(Request $request,CryptoNewsService $CryptoNewsService,CryptoNewsValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('delete')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['id'] = $request->param('id', null);
        $arrData = $CryptoNewsService->delete($param);
        return json($arrData);
    }

    /**
     * 新闻发布
     * @param Request $request
     * @param CryptoNewsService $CryptoNewsService
     * @param CryptoNewsValidate $validate
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 2024-10-23 15:34:36
     * author: jiang
     */
    public function publish(Request $request,CryptoNewsService $CryptoNewsService,CryptoNewsValidate $validate){
        $checkData = $request->param();
        if (!$validate->scene('publish')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['id'] = $request->param('id',null);
        $param['platform'] = $request->param('platform',null);
        $param['cue_word'] = $request->param('cue_word','');
        $param['language'] = $request->param('language',null);
        $param['associatedMiners'] = $request->param('associatedMiners','');

        $arrData = $CryptoNewsService->publish($param);
        return json($arrData);
    }

    /**
     * 服务器列表
     * @param Request $request
     * @param CryptoNewsService $CryptoNewsService
     * @param CryptoNewsValidate $validate
     * @return \think\response\Json
     * 2024-10-23 15:34:21
     * author: jiang
     */
    public function machineList(Request $request,CryptoNewsService $CryptoNewsService,CryptoNewsValidate $validate){
        $arrData = $CryptoNewsService->machineList();
        return json($arrData);
    }

    /**
     * 智能搜索
     * @param Request $request
     * @param CryptoNewsService $CryptoNewsService
     * @param CryptoNewsValidate $validate
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 2024-10-23 15:34:02
     * author: jiang
     */
    public function searchNews(Request $request,CryptoNewsService $CryptoNewsService,CryptoNewsValidate $validate){
        $param['operator_id'] = $request->operator_id;
        $checkData = $request->param();
        if (!$validate->scene('searchNews')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['id'] = $request->param('id',null);
        $arrData = $CryptoNewsService->searchNews($param);
        return json($arrData);
    }
}
?>
